package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: 12629
 * Date: 2022/2/25
 * Time: 21:54
 * Description:
 */
public class ReturnOperation implements IOperation{

    public void work(BookList bookList) {
        System.out.println("归还书籍！");
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入你要归还的书籍:");
        String name = scanner.nextLine();

        int currentSize = bookList.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)) {
                book.setBorrowed(false);
                System.out.println("归还成功,归还书籍信息如下：");
                System.out.println(book);
                return;
            }
        }
        System.out.println("归还失败，没有这本书！");
    }

}
